#include <vector>
#include <algorithm>

using namespace std;

class Solution
{
public:
    struct Com
    {
        bool operator()(vector<int> &a, vector<int> &b)
        {
            return a[1] < b[1];
        }
    };
    int findLongestChain(vector<vector<int>> &pairs)
    {
        int res = 1;
        sort(pairs.begin(), pairs.end(), Com());
        int pre = pairs[0][1];
        for (int i = 1; i < pairs.size(); ++i)
        {
            int cur = pairs[i][0];
            if (cur > pre)
            {
                ++res;
                pre = pairs[i][1];
            }
        }
        return res;
    }
};